﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TotalSystems.DataAccess;
using TotalSystems.Business.Public;

namespace TotalSystems.Business.Store
{
	public class UnitStuffRepository
	{
        TSContext _context = new TSContext();
        FinancialYearRepository financialYearRepository = new Public.FinancialYearRepository();

        #region Select
        public IEnumerable<STR_UnitStuff> GetUnitStuff()
        {
            return _context.STR_UnitStuff;
        }

        #endregion

        #region Insert

        public void InsertUnitStuff(STR_UnitStuff sTR_UnitStuff)
        {
            sTR_UnitStuff.ACC_Fy_ID_fk = financialYearRepository.GetACC_FinancialYearActive().Select(x => x.ACC_Fy_ID_fk).First();
            _context.AddToSTR_UnitStuff(sTR_UnitStuff);
            _context.SaveChanges();
        }

        #endregion

        #region Update

        public void UpdateUnitStuff(STR_UnitStuff sTR_UnitStuff)
        {
            var q = _context.STR_UnitStuff.FirstOrDefault(x => x.STR_Us_ID == sTR_UnitStuff.STR_Us_ID);
            _context.STR_UnitStuff.ApplyCurrentValues(q);
            _context.SaveChanges();
        }

        #endregion
	}
}
